/*
 * Base on MailNode.java
 */
package spe.jbpm.gd.jpdl.model;

import java.util.ArrayList;
import java.util.List;

public class DocumentNode extends AbstractNode implements DocumentStateVariableContainer, AsyncableElement {
	
	private String documentId;
	private String documentName;
	private String documentAttribute;	

	private DocumentState documentState;
	
	private List variables = new ArrayList();
	
	//-- Test DocumentState for Document Info
	public void setDocumentState(DocumentState newDocumentState) {
		DocumentState oldDocumentState = documentState;
		documentState = newDocumentState;
		firePropertyChange("document-state", oldDocumentState, newDocumentState);
	}	
	public DocumentState getDocumentState() {
		return documentState;
	}
	
	// Add multi document state element
	public void addDocumentState(DocumentState documentState) {
		variables.add(documentState);
		firePropertyChange("documentStateAdd", null, documentState);
	}	
	public void removeDocumentState(DocumentState documentState) {
		variables.remove(documentState);
		firePropertyChange("documentStateRemove", documentState, null);
	}
	public DocumentState[] getDocumentStates() {
		return (DocumentState[])variables.toArray(new DocumentState[variables.size()]);
	}	
	// End adding
	
	//-- Document Id
	public void setDocumentId(String newDocumentId) {
		String oldDocumentId = documentId;
		documentId = newDocumentId;
		firePropertyChange("documentId", oldDocumentId, newDocumentId);
	}	
	public String getDocumentId() {
		return documentId;
	}
	
	//-- Document Name
	public void setDocumentName(String newDocumentName) {
		String oldDocumentName = documentName;
		documentName = newDocumentName;
		firePropertyChange("documentName", oldDocumentName, newDocumentName);
	}	
	public String getDocumentName() {
		return documentName;
	}
	
	//-- Document Attribute
	public void setDocumentAttribute(String newDocumentAttribute) {
		String oldDocumentAttribute = documentAttribute;
		documentAttribute = newDocumentAttribute;
		firePropertyChange("documentAttribute", oldDocumentAttribute, newDocumentAttribute);
	}	
	public String getDocumentAttribute() {
		return documentAttribute;
	}	
	
	private Handler handler;
	private String expression;
	
	private String async;

	public void setAsync(String newAsync) {
		String oldAsync = async;
		async = newAsync;
		firePropertyChange("async", oldAsync, newAsync);
	}
	
	public String getAsync() {
		return async;
	}
	
	public void setHandler(Handler newHandler) {
		Handler oldHandler = handler;
		handler = newHandler;
		firePropertyChange("handler", oldHandler, newHandler);
	}
	
	public Handler getHandler() {
		return handler;
	}
	
	public void setExpression(String newExpression) {
		String oldExpression = expression;
		expression = newExpression == null ? null : newExpression.trim();
		firePropertyChange("expression", oldExpression, expression);
	}
	
	public String getExpression() {
		return expression;
	}




}